<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/security/tags" prefix="security" %>
<!-- 跳转添加页的按钮 -->
<c:set var="TO_ADD_BUTTON" value="${CODE_AUTH.user_to_add_button}"></c:set>
<!-- 跳转修改页的按钮 -->
<c:set var="TO_EDIT_BUTTON" value="${CODE_AUTH.user_to_edit_button}"></c:set>
<!-- 删除按钮 -->
<c:set var="DELETE_BUTTON" value="${CODE_AUTH.user_delete_button}"></c:set>
<!-- 跳转分配角色页面的按钮 -->
<c:set var="TO_ASSIGN_ROLE_BUTTON" value="${CODE_AUTH.user_to_assign_role_button}" ></c:set>
<!-- 是否有跳转添加页的权限 -->
<security:authorize var="HAS_AUTH_TO_ADD" access="${TO_ADD_BUTTON.SPEL}"></security:authorize>	
<!-- 是否有跳转修改页的权限 -->				
<security:authorize var="HAS_AUTH_TO_EDIT" access="${TO_EDIT_BUTTON.SPEL}"></security:authorize>
<!-- 是否有删除的权限 -->						
<security:authorize var="HAS_AUTH_DELETE" access="${DELETE_BUTTON.SPEL}"></security:authorize>	
<!-- 是否有跳转分配角色页面的权限 -->				
<security:authorize var="HAS_AUTH_TO_ASSIGN_ROLE" access="${TO_ASSIGN_ROLE_BUTTON.SPEL}"></security:authorize>					
<!DOCTYPE html>
<html lang="zh-CN">
<!-- 引入头部 -->
<%@include file="/WEB-INF/include-head.jsp"%>
<link rel="stylesheet" href="css/pagination.css">
<script type="text/javascript" src="jquery/jquery.pagination.js"></script>
<script type="text/javascript">
$(function(){
	
	// 初始化jquery分页插件
	initPagination();
	
});

// 初始化jquery分页插件
function initPagination(){
	// 获取总记录数
	var totalRecord = "${requestScope.pageInfo.total}";
	// 创建分页条
	$("#Pagination").pagination(totalRecord, {
		num_edge_entries: 1, 											// 边缘页数
		num_display_entries: 4, 										// 主体页数
		items_per_page:Number("${requestScope.pageInfo.pageSize}"), 	// 每页显示的条目数
		current_page:Number("${requestScope.pageInfo.pageNum -1 }"), 	// 当前选中的页面
		prev_text:"上一页",												// “前一页”分页按钮上显示的文字
		next_text:"下一页",												// “下一页”分页按钮上显示的文字
		callback: function(pageIndex, jQuery){							// 回调函数
			// 根据pageIndex计算得到pageNum
			var pageNum = pageIndex + 1;
			// 跳转页面
			window.location.href = "admin/get/page.html?pageNum=" + pageNum + "&keyword=${param.keyword}";
			return false;
		}
	});
}

</script>
<body>
	<!-- 引入导航条 -->
	<%@include file="/WEB-INF/include-nav.jsp"%>
	<div class="container-fluid">
		<div class="row">
			<!-- 引入侧边栏 -->
			<%@include file="/WEB-INF/include-sidebar.jsp"%>
			<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
			${requestScope.requestScope.pageInfo}
				<!-- 内容开始 -->
				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">
							<i class="glyphicon glyphicon-th"></i> 数据列表
						</h3>
						<%-- <div>
							${TO_ADD_BUTTON}<br>
							${TO_EDIT_BUTTON}<br>
							${DELETE_BUTTON}<br>
							${TO_ASSIGN_ROLE_BUTTON}<br>
						</div> --%>
					</div>
					<div class="panel-body">
						<form action="admin/get/page.html" method="post" class="form-inline" role="form" style="float: left;">
							<!-- csrf隐藏域 -->
							<input type="hidden" name="${_csrf.parameterName }" value="${_csrf.token }"/>
			
							<div class="form-group has-feedback">
								<div class="input-group">
									<div class="input-group-addon">查询条件</div>
									<input name="keyword" value="${param.keyword}" class="form-control has-success" type="text"
										placeholder="请输入查询条件">
								</div>
							</div>
							<button type="submit" class="btn btn-warning">
								<i class="glyphicon glyphicon-search"></i> 查询
							</button>
						</form>
						<security:authorize access="${HAS_AUTH_DELETE}">
							<a class="${DELETE_BUTTON.BUTTON_CLASS }" style="float: right; margin-left: 10px;">
								<i class="${DELETE_BUTTON.ICON_CLASS }"></i> 删除
							</a>
						</security:authorize>
						<security:authorize access="${HAS_AUTH_TO_ADD}">
							<a href="${TO_ADD_BUTTON.URL }" class="${TO_ADD_BUTTON.BUTTON_CLASS }" style="float: right;">
								<i class="${TO_ADD_BUTTON.ICON_CLASS }"></i> 新增
							</a>
						</security:authorize>
						<br>
						<hr style="clear: both;">
						<div class="table-responsive">
							<table class="table  table-bordered">
								<thead>
									<tr>
										<th width="30">#</th>
										<th width="30"><input type="checkbox"></th>
										<th>账号</th>
										<th>名称</th>
										<th>邮箱地址</th>
										<th width="100">操作</th>
									</tr>
								</thead>
								<tbody>
									<c:if test="${empty requestScope.pageInfo.list }">
										<tr>
											<td colspan="6" align="center">抱歉！没有查询到您要的数据！</td>
										</tr>
									</c:if>
									<c:if test="${!empty requestScope.pageInfo.list }">
										<c:forEach var="admin" items="${requestScope.pageInfo.list}" varStatus="myStatus">
											<tr>
												<td>${myStatus.count}</td>
												<td><input type="checkbox"></td>
												<td>${admin.loginAcct}</td>
												<td>${admin.userName}</td>
												<td>${admin.email}</td>
												<td>
													<security:authorize access="${HAS_AUTH_TO_ASSIGN_ROLE}">
														<a href="${TO_ASSIGN_ROLE_BUTTON.URL}?adminId=${admin.id}&pageNum=${requestScope.pageInfo.pageNum}&keyword=${param.keyword}" 
															title="分配角色" class="${TO_ASSIGN_ROLE_BUTTON.BUTTON_CLASS} btn-xs">
															<i class="${TO_ASSIGN_ROLE_BUTTON.ICON_CLASS}"></i>
														</a>
													</security:authorize>
													<security:authorize access="${HAS_AUTH_TO_EDIT }">
														<a href="${TO_EDIT_BUTTON.URL }?id=${admin.id}&pageNum=${requestScope.pageInfo.pageNum}&keyword=${param.keyword}" 
															title="修改" class="${TO_EDIT_BUTTON.BUTTON_CLASS } btn-xs">
															<i class="${TO_EDIT_BUTTON.ICON_CLASS }"></i>
														</a>
													</security:authorize>
													<security:authorize access="${HAS_AUTH_DELETE }">
														<a href="admin/remove/${admin.id}/${requestScope.pageInfo.pageNum}/${param.keyword}.html" 
															title="删除" class="${DELETE_BUTTON.BUTTON_CLASS } btn-xs">
															<i class="${DELETE_BUTTON.ICON_CLASS }"></i>
														</a>
													</security:authorize>
												</td>
											</tr>
										</c:forEach>
										
									</c:if>
								</tbody>
								<tfoot>
									<tr>
										<td colspan="6" align="center">
										
											<div class="pull-left" style="margin: 20px 0;padding: 6px 0;position: absolute;left: 65px;">
												当前 <b>${requestScope.pageInfo.pageNum}</b> 页
												，总 <b>${requestScope.pageInfo.pages}</b> 页
												，总 <b>${requestScope.pageInfo.total}</b> 条记录
											</div>
				
											<%-- 
											<ul class="pagination">
												<c:if test="${requestScope.pageInfo.pageNum > 1 }">
													<li><a href="admin/get/page.html?pageNum=${requestScope.pageInfo.pageNum - 1 }">上一页</a></li>
												</c:if>
												<c:if test="${requestScope.pageInfo.pageNum <= 1 }">
													<li class="disabled"><a>上一页</a></li>
												</c:if>
												<c:forEach begin="1" end="${requestScope.pageInfo.pages}" var="page">
													<c:if test="${page == requestScope.pageInfo.pageNum }">
														<li class="active"><a href="admin/get/page.html?pageNum=${page}">${page}</a></li>
													</c:if>
													<c:if test="${page != requestScope.pageInfo.pageNum }">
														<li><a href="admin/get/page.html?pageNum=${page}">${page}</a></li>
													</c:if>
												</c:forEach>
												<c:if test="${requestScope.pageInfo.pageNum < requestScope.pageInfo.pages }">
													<li><a href="admin/get/page.html?pageNum=${requestScope.pageInfo.pageNum + 1 }">下一页</a></li>
												</c:if>
												<c:if test="${requestScope.pageInfo.pageNum >= requestScope.pageInfo.pages }">
													<li class="disabled"><a>下一页</a></li>
												</c:if>
											</ul>
											 --%>
											
											<div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
											
										</td>
									</tr>

								</tfoot>
							</table>
						</div>
					</div>
				</div>
				<!-- 内容结束 -->




			</div>
		</div>
	</div>
</body>
</html>